home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / PSBMAP.H < prev    next >
C/C++ Source or Header  |  1992-04-17  |  7KB  |  265 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/psbmap.h,v 9.37 1992/04/18 00:30:02 jinx Exp $
  4.  
  5. Copyright (c) 1987-1992 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* This file contains macros and declarations for "Bintopsb.c"
  36.    and "Psbtobin.c". */
  37.  
  38. #ifndef PSBMAP_H_INCLUDED
  39. #define PSBMAP_H_INCLUDED
  40.  
  41. /* These definitions insure that the appropriate code is extracted
  42.    from the included files.
  43. */
  44.  
  45. #define fast register
  46.  
  47. #include <stdio.h>
  48. #include "ansidecl.h"
  49. #include "config.h"
  50. #include "types.h"
  51. #include "object.h"
  52. #include "bignum.h"
  53. #include "bignumint.h"
  54. #include "bitstr.h"
  55. #include "sdata.h"
  56. #include "const.h"
  57. #include "gccode.h"
  58. #define boolean Boolean
  59. #include "comlin.h"
  60.  
  61. extern double
  62.   EXFUN (frexp, (double, int *)),
  63.   EXFUN (ldexp, (double, int));
  64.  
  65. #define PORTABLE_VERSION    5
  66.  
  67. /* Number of objects which, when traced recursively, point at all other
  68.    objects dumped.  Currently only the dumped object.
  69.  */
  70.  
  71. #define NROOTS            1
  72.  
  73. /* Types to recognize external object references.  Any occurrence of these
  74.    (which are external types and thus handled separately) means a reference
  75.    to an external object.
  76.  */
  77.  
  78. #define CONSTANT_CODE            TC_FIXNUM
  79. #define HEAP_CODE            TC_CHARACTER
  80.  
  81. #define fixnum_to_bits            FIXNUM_LENGTH
  82. #define hex_digits(nbits)        (((nbits) + 3) / 4)
  83.  
  84. #define to_pointer BYTES_TO_WORDS
  85.  
  86. #define float_to_pointer                        \
  87.   BYTES_TO_WORDS(sizeof(double))
  88.  
  89. #ifndef FLOATING_ALIGNMENT
  90.  
  91. #define flonum_to_pointer(nfloats)                    \
  92.   ((nfloats) * (1 + float_to_pointer))
  93.  
  94. #else /* FLOATING_ALIGNMENT */
  95.  
  96. /* When computing the space needed for flonums, the worst case is that
  97.    every flonum needs alignment.  To estimate the space needed, add
  98.    padding to each flonum to round it up to an alignment boundary.  */
  99.  
  100. #define flonum_to_pointer(nfloats)                    \
  101.   ((nfloats)                                \
  102.    * (((((1 + float_to_pointer) * (sizeof (char)))            \
  103.     & FLOATING_ALIGNMENT)                        \
  104.        == 0)                                \
  105.       ? (1 + float_to_pointer)                        \
  106.       : ((((1 + float_to_pointer) * (sizeof (char)))            \
  107.       + ((FLOATING_ALIGNMENT + 1)                    \
  108.          - (((1 + float_to_pointer) * (sizeof (char)))        \
  109.         & FLOATING_ALIGNMENT)))                    \
  110.      / (sizeof (char)))))
  111.  
  112. #endif /* FLOATING_ALIGNMENT */
  113.  
  114. #define char_to_pointer(nchars)                        \
  115.   BYTES_TO_WORDS(nchars)
  116.  
  117. #define pointer_to_char(npoints)                    \
  118.   ((npoints) * sizeof(SCHEME_OBJECT))
  119.  
  120. /* Status flags */
  121.  
  122. #define COMPACT_P    (1 << 0)
  123. #define NULL_NMV_P    (1 << 1)
  124. #define COMPILED_P    (1 << 2)
  125. #define NMV_P        (1 << 3)
  126. #define BAND_P        (1 << 4)
  127.  
  128. #define MAKE_FLAGS()                            \
  129. ((compact_p ? COMPACT_P : 0)    |                    \
  130.  (null_nmv_p ? NULL_NMV_P : 0)    |                    \
  131.  (compiled_p ? COMPILED_P : 0)    |                    \
  132.  (nmv_p ? NMV_P : 0)        |                    \
  133.  (band_p ? BAND_P : 0))
  134.  
  135. #define READ_FLAGS(f)                            \
  136. {                                    \
  137.   compact_p = ((f) & COMPACT_P);                    \
  138.   null_nmv_p  = ((f) & NULL_NMV_P);                    \
  139.   compiled_p = ((f) & COMPILED_P);                    \
  140.   nmv_p = ((f) & NMV_P);                        \
  141.   band_p = ((f) & BAND_P);                        \
  142. }
  143.  
  144. /*
  145.   If true, make all integers fixnums if possible, and all strings as
  146.   short as possible (trim extra stuff).
  147.  */
  148.  
  149. static Boolean compact_p = true;
  150.  
  151. /* If true, null out all elements of random non-marked vectors. */
  152.  
  153. static Boolean null_nmv_p = false;
  154.  
  155. /* If true, the portable file contains compiled code. */
  156.  
  157. static Boolean compiled_p = false;
  158.  
  159. /* If true, the portable file contains "random" non-marked vectors. */
  160.  
  161. static Boolean nmv_p = false;
  162.  
  163. /* Global data */
  164.  
  165. #ifndef HEAP_IN_LOW_MEMORY
  166. SCHEME_OBJECT * memory_base;
  167. #endif
  168.  
  169. static long
  170.   compiler_processor_type = 0,
  171.   compiler_interface_version = 0;
  172.  
  173. static SCHEME_OBJECT
  174.   compiler_utilities = SHARP_F;
  175.  
  176. /* Utilities */
  177.  
  178. static char
  179.   *input_file_name = "-",
  180.   *output_file_name = "-";
  181.  
  182. FILE *input_file, *output_file;
  183.  
  184. Boolean
  185. DEFUN (strequal, (s1, s2), register char * s1 AND register char * s2)
  186. {
  187.   for ( ; *s1 != '\0'; s1++, s2++)
  188.   {
  189.     if (*s1 != *s2)
  190.     {
  191.       return (false);
  192.     }
  193.   }
  194.   return (*s2 == '\0');
  195. }
  196.  
  197. void
  198. DEFUN (setup_io, (input_mode, output_mode),
  199.        CONST char * input_mode AND CONST char * output_mode)
  200. {
  201.   if (strequal (input_file_name, "-"))
  202.   {
  203.     input_file = stdin;
  204.   }
  205.   else
  206.   {
  207.     input_file = (fopen (input_file_name, input_mode));
  208.     if (input_file == ((FILE *) NULL))
  209.     {
  210.       fprintf (stderr, "%s: failed to open %s for input.\n",
  211.            program_name, input_file_name);
  212.       exit (1);
  213.     }
  214.   }
  215.  
  216.   if (strequal (output_file_name, "-"))
  217.   {
  218.     output_file = stdout;
  219.   }
  220.   else
  221.   {
  222.     output_file = (fopen (output_file_name, output_mode));
  223.     if (output_file == ((FILE *) NULL))
  224.     {
  225.       fprintf (stderr, "%s: failed to open %s for output.\n",
  226.            program_name, output_file_name);
  227.       fclose (input_file);
  228.       exit (1);
  229.     }
  230.   }
  231.   return;
  232. }
  233.  
  234. void
  235. DEFUN (quit, (code), int code)
  236. {
  237.   fclose(input_file);
  238.   fclose(output_file);
  239. #ifdef vms
  240.   /* This assumes that it is only invoked with 0 in tail recursive psn. */
  241.   if (code != 0)
  242.   {
  243.     exit(code);
  244.   }
  245.   else
  246.   {
  247.     return;
  248.   }
  249. #else /* not vms */
  250.   exit(code);
  251. #endif /*vms */
  252. }
  253.  
  254. /* Include the command line parser */
  255.  
  256. #include "comlin.c"
  257.  
  258. #define INPUT_KEYWORD()                        \
  259. KEYWORD("input", &input_file_name, STRING_KYWRD, SFRMT, NULL)
  260.  
  261. #define OUTPUT_KEYWORD()                    \
  262. KEYWORD("output", &output_file_name, STRING_KYWRD, SFRMT, NULL)
  263.  
  264. #endif /* PSBMAP_H_INCLUDED */
  265.